<?
class ClamAV extends AV {
    var $cmd='/usr/bin/sudo -b /usr/bin/clamscan';
    var $file_stats='/tmp/garbirus_clam_stats';

    function AV (){
        parent::__construct();
    }

    function setEngine(){
        //
        // sets AV description+version in '$this->engine'
        //

        $version=exec($this->cmd." -V");
        $this->engine=$version;
    }

    function startAnalyzer($path){
        # Generate empty stats file
        touch($this->file_stats);
        # Start analyzing...
        $result=exec($this->cmd." --quiet --recursive --log=".$this->file_stats." --bell  ".$path. " > /dev/null &");
        return "Analyze started with ".$this->engine;
    }

    function isRunning(){
        $status=exec("/bin/ps aux |grep -v grep |grep -qs clamscan && echo $?");
        if ($status == "0"){
            return true;
        } else {
            return false;
        }

    }

    function printStats(){
        $stats=file($this->file_stats, FILE_SKIP_EMPTY_LINES);
        $this->destroyAnalyzer();
        return $stats;
    }

    function destroyAnalyzer(){
        // Delete stats file
        unlink($this->file_stats);
    }
}
?>
